angular.module('pa.service', [])
.factory('PA',['$http', function($http){
    return {
        getSubnet: function(callback){
            $http.get('/_api/subnet').
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },     
        getHostsBySubnet: function(sb,callback){
            $http.get('/_api/sb/'+sb).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        getHostByIP: function(ip,callback){
            $http.get('/_api/ip/'+ip).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        }               
    };
}])
.factory('Utils',['$http', function($http){
    return {
    ip2network: function(ip){
        var iparr = ip.split('.');
        return [iparr[0],iparr[1],iparr[2],'0'].join('.');
    }
}
}]);

